/**
 * <copyright>
 * </copyright>
 *
 * $Id: EJBImpl.java,v 1.5 2008/11/19 02:38:11 song Exp $
 */
package cn.edu.pku.sei.ra.wrapping.JOnAS.impl;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.List;

import javax.enterprise.deploy.model.DDBean;
import javax.enterprise.deploy.model.DDBeanRoot;
import javax.enterprise.deploy.model.DeployableObject;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
import javax.enterprise.deploy.spi.DConfigBeanRoot;
import javax.enterprise.deploy.spi.DeploymentConfiguration;
import javax.enterprise.deploy.spi.DeploymentManager;
import javax.enterprise.deploy.spi.Target;
import javax.enterprise.deploy.spi.TargetModuleID;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.j2ee.Management;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import cn.edu.pku.sei.ra.wrapping.JOnAS.EJB;
import cn.edu.pku.sei.ra.wrapping.JOnAS.JOnASPackage;

import java.util.Collection;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;

import org.apache.xerces.dom.DOMImplementationImpl;
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
import org.apache.xerces.jaxp.DocumentBuilderImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.apache.xpath.XPathAPI;
import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;
import org.objectweb.dolphin.resources.JarUtils;
import org.objectweb.dolphin.resources.deploy.model.AbstractDeployable;
import org.objectweb.ishmael.deploy.spi.dconfigbean.IshmaelDConfigBeanRoot;
import org.objectweb.ishmael.deploy.spi.dconfigbean.common.ResourceDConfigBean;
import org.objectweb.ishmael.deploy.spi.dconfigbean.ejbjar.entity.EntityDConfigBean;
import org.objectweb.ishmael.deploy.spi.factories.DeploymentFactoryImpl;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import org.w3c.dom.traversal.NodeIterator;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>EJB</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getJndiName <em>Jndi Name</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getFileName <em>File Name</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getLocalClass <em>Local Class</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getLocalHomeClass <em>Local Home Class</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getHomeClass <em>Home Class</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getEjbClass <em>Ejb Class</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getCacheSize <em>Cache Size</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getPoolSize <em>Pool Size</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getMaxCacheSize <em>Max Cache Size</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getMinPoolSize <em>Min Pool Size</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getDisplayName <em>Display Name</em>}</li>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.EJBImpl#getDataSourceJNDI <em>Data Source JNDI</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EJBImpl extends J2EEManagedObjectImpl implements EJB {
	/**
	 * The default value of the '{@link #getJndiName() <em>Jndi Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getJndiName()
	 * @generated
	 * @ordered
	 */
	protected static final String JNDI_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getJndiName() <em>Jndi Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getJndiName()
	 * @generated
	 * @ordered
	 */
	protected String jndiName = JNDI_NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getFileName() <em>File Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFileName()
	 * @generated
	 * @ordered
	 */
	protected static final String FILE_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getFileName() <em>File Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFileName()
	 * @generated
	 * @ordered
	 */
	protected String fileName = FILE_NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getLocalClass() <em>Local Class</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLocalClass()
	 * @generated
	 * @ordered
	 */
	protected static final String LOCAL_CLASS_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getLocalClass() <em>Local Class</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLocalClass()
	 * @generated
	 * @ordered
	 */
	protected String localClass = LOCAL_CLASS_EDEFAULT;

	/**
	 * The default value of the '{@link #getLocalHomeClass() <em>Local Home Class</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLocalHomeClass()
	 * @generated
	 * @ordered
	 */
	protected static final String LOCAL_HOME_CLASS_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getLocalHomeClass() <em>Local Home Class</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLocalHomeClass()
	 * @generated
	 * @ordered
	 */
	protected String localHomeClass = LOCAL_HOME_CLASS_EDEFAULT;

	/**
	 * The default value of the '{@link #getHomeClass() <em>Home Class</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getHomeClass()
	 * @generated
	 * @ordered
	 */
	protected static final String HOME_CLASS_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getHomeClass() <em>Home Class</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getHomeClass()
	 * @generated
	 * @ordered
	 */
	protected String homeClass = HOME_CLASS_EDEFAULT;

	/**
	 * The default value of the '{@link #getEjbClass() <em>Ejb Class</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEjbClass()
	 * @generated
	 * @ordered
	 */
	protected static final String EJB_CLASS_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getEjbClass() <em>Ejb Class</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEjbClass()
	 * @generated
	 * @ordered
	 */
	protected String ejbClass = EJB_CLASS_EDEFAULT;

	/**
	 * The default value of the '{@link #getCacheSize() <em>Cache Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCacheSize()
	 * @generated
	 * @ordered
	 */
	protected static final int CACHE_SIZE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getCacheSize() <em>Cache Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCacheSize()
	 * @generated
	 * @ordered
	 */
	protected int cacheSize = CACHE_SIZE_EDEFAULT;

	/**
	 * The default value of the '{@link #getPoolSize() <em>Pool Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPoolSize()
	 * @generated
	 * @ordered
	 */
	protected static final int POOL_SIZE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getPoolSize() <em>Pool Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPoolSize()
	 * @generated
	 * @ordered
	 */
	protected int poolSize = POOL_SIZE_EDEFAULT;

	/**
	 * The default value of the '{@link #getMaxCacheSize() <em>Max Cache Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaxCacheSize()
	 * @generated
	 * @ordered
	 */
	protected static final int MAX_CACHE_SIZE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getMaxCacheSize() <em>Max Cache Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaxCacheSize()
	 * @generated
	 * @ordered
	 */
	protected int maxCacheSize = MAX_CACHE_SIZE_EDEFAULT;

	/**
	 * The default value of the '{@link #getMinPoolSize() <em>Min Pool Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMinPoolSize()
	 * @generated
	 * @ordered
	 */
	protected static final int MIN_POOL_SIZE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getMinPoolSize() <em>Min Pool Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMinPoolSize()
	 * @generated
	 * @ordered
	 */
	protected int minPoolSize = MIN_POOL_SIZE_EDEFAULT;

	/**
	 * The default value of the '{@link #getDisplayName() <em>Display Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDisplayName()
	 * @generated
	 * @ordered
	 */
	protected static final String DISPLAY_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getDisplayName() <em>Display Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDisplayName()
	 * @generated
	 * @ordered
	 */
	protected String displayName = DISPLAY_NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getDataSourceJNDI() <em>Data Source JNDI</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataSourceJNDI()
	 * @generated
	 * @ordered
	 */
	protected static final String DATA_SOURCE_JNDI_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getDataSourceJNDI() <em>Data Source JNDI</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataSourceJNDI()
	 * @generated
	 * @ordered
	 */
	protected String dataSourceJNDI = DATA_SOURCE_JNDI_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EJBImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return JOnASPackage.Literals.EJB;
	}

	public Object createCore(){
		if(fileName!=null && fileName.endsWith("jar")){
			Management mgmt=JOnASPackage.eINSTANCE.getMainEntry();
			ObjectName query;
			try {
				this.setNewborn(false);
				String[] signature={"java.lang.String"};
				String[] params=new String[1];
				params[0] = fileName;
				query = new ObjectName("jonas:j2eeType=J2EEServer,*");
				ObjectName server=(ObjectName)mgmt.queryNames(query, null).iterator().next();
				String deployedName=(String)mgmt.invoke(server, "deployJar", params, signature);
				query=new ObjectName(deployedName);
				ObjectName module=(ObjectName)mgmt.queryNames(query, null).iterator().next();
				String[] allEjb=(String[])mgmt.getAttribute(module, "ejbs");
				
				String qString=allEjb[0];
				query=new ObjectName(qString+",*");
				ObjectName res=(ObjectName)mgmt.queryNames(query, null).iterator().next();
				return res;
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} 
		}
		return null;
	}

	public void destroyCore(){
		if(core==null)
			return;
		getFileName();
		if(fileName!=null && fileName.endsWith("jar")){
			Management mgmt=JOnASPackage.eINSTANCE.getMainEntry();
			ObjectName query;
			try {
				this.setCore(null);
				this.setNewborn(false);
				String[] signature={"java.lang.String"};
				String[] params=new String[1];
				params[0] = fileName;
				query = new ObjectName("jonas:j2eeType=J2EEServer,*");
				ObjectName server=(ObjectName)mgmt.queryNames(query, null).iterator().next();
				mgmt.invoke(server, "unDeployJar", params, signature);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		}
	}

	
	
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getJndiName() {
		if(getCore()==null) return "";
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			jndiName=(String)mainEntry.getAttribute(obj, "jndiName");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return jndiName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void setJndiName(String newJndiName) {
		String oldJndiName = jndiName;
		jndiName = newJndiName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__JNDI_NAME, oldJndiName, jndiName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getFileName() {
		if(getCore()==null) return "";
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			fileName=(String)mainEntry.getAttribute(obj, "fileName");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return fileName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void setFileName(String newFileName) {
		String oldFileName = fileName;
		fileName = newFileName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__FILE_NAME, oldFileName, fileName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getLocalClass() {
		if(getCore()==null) return "";
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			localClass=(String)mainEntry.getAttribute(obj, "localClass");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return localClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void setLocalClass(String newLocalClass) {
		String oldLocalClass = localClass;
		localClass = newLocalClass;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__LOCAL_CLASS, oldLocalClass, localClass));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getLocalHomeClass() {
		if(getCore()==null) return "";
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			localHomeClass=(String)mainEntry.getAttribute(obj, "localHomeClass");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return localHomeClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void setLocalHomeClass(String newLocalHomeClass) {
		String oldLocalHomeClass = localHomeClass;
		localHomeClass = newLocalHomeClass;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__LOCAL_HOME_CLASS, oldLocalHomeClass, localHomeClass));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getHomeClass() {
		if(getCore()==null) return "";
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			homeClass=(String)mainEntry.getAttribute(obj, "homeClass");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return homeClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void setHomeClass(String newHomeClass) {
		String oldHomeClass = homeClass;
		homeClass = newHomeClass;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__HOME_CLASS, oldHomeClass, homeClass));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getEjbClass() {
		if(getCore()==null) return "";
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			ejbClass=(String)mainEntry.getAttribute(obj, "ejbClass");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ejbClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void setEjbClass(String newEjbClass) {
		String oldEjbClass = ejbClass;
		ejbClass = newEjbClass;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__EJB_CLASS, oldEjbClass, ejbClass));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public int getCacheSize() {
		if(getCore()==null) return -1;
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			cacheSize=((Integer)mainEntry.getAttribute(obj, "cacheSize")).intValue();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return cacheSize;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void setCacheSize(int newCacheSize) {
		int oldCacheSize = cacheSize;
		cacheSize = newCacheSize;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__CACHE_SIZE, oldCacheSize, cacheSize));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public int getPoolSize() {
		if(getCore()==null) return -1;
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			poolSize=((Integer)mainEntry.getAttribute(obj, "poolSize")).intValue();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return poolSize;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPoolSize(int newPoolSize) {
		int oldPoolSize = poolSize;
		poolSize = newPoolSize;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__POOL_SIZE, oldPoolSize, poolSize));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public int getMaxCacheSize() {
		if(getCore()==null) return -1;
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			maxCacheSize=((Integer)mainEntry.getAttribute(obj, "maxCacheSize")).intValue();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return maxCacheSize;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMaxCacheSize(int newMaxCacheSize) {
		int oldMaxCacheSize = maxCacheSize;
		maxCacheSize = newMaxCacheSize;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__MAX_CACHE_SIZE, oldMaxCacheSize, maxCacheSize));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public int getMinPoolSize() {
		if(getCore()==null) return -1;
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			minPoolSize=((Integer)mainEntry.getAttribute(obj, "minPoolSize")).intValue();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return minPoolSize;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMinPoolSize(int newMinPoolSize) {
		int oldMinPoolSize = minPoolSize;
		minPoolSize = newMinPoolSize;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__MIN_POOL_SIZE, oldMinPoolSize, minPoolSize));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getDisplayName() {
		if(getCore()==null) return "";
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			displayName=(String)mainEntry.getAttribute(obj, "displayName");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return displayName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void setDisplayName(String newDisplayName) {
		String oldDisplayName = displayName;
		displayName = newDisplayName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__DISPLAY_NAME, oldDisplayName, displayName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getDataSourceJNDI() {
		if(getCore()==null) return "";
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			Hashtable hs=(Hashtable)mainEntry.getAttribute(obj, "allDataSourceName");
			dataSourceJNDI=hs.keySet().iterator().next().toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			dataSourceJNDI=null;
		}
		return dataSourceJNDI;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @throws IOException 
	 * @generated NOT
	 */
	public void setDataSourceJNDI(String newDataSourceJNDI) {
		String oldDataSourceJNDI = dataSourceJNDI;
		dataSourceJNDI = newDataSourceJNDI;
		getFileName();
		if(dataSourceJNDI!=null && !dataSourceJNDI.equals(oldDataSourceJNDI)){
			Management mgmt=JOnASPackage.eINSTANCE.getMainEntry();
			ObjectName query;
			try {
				String[] signature={"java.lang.String"};
				String[] params=new String[1];
				params[0] = fileName;
				query = new ObjectName("jonas:j2eeType=J2EEServer,*");
				ObjectName server=(ObjectName)mgmt.queryNames(query, null).iterator().next();
				mgmt.invoke(server, "unDeployJar", params, signature);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
			JarFile jar;
			try {
				jar = new JarFile(fileName);
				JarEntry entry=jar.getJarEntry("META-INF/jonas-ejb-jar.xml");
				InputStream is=jar.getInputStream(entry);
				DOMImplementation impl 
			       = DOMImplementationImpl.getDOMImplementation();
				DocumentBuilderFactory factory= DocumentBuilderFactoryImpl.newInstance();
				DocumentBuilder db=factory.newDocumentBuilder();
				Document doc=db.parse(is);
				is.close();
				jar.close();
				String xpathString="jonas-ejb-jar/jonas-entity/jonas-resource/jndi-name";
				//Node nd1=doc.getDocumentElement().getFirstChild().getFirstChild();
				NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpathString);
				Element nd=(Element)nl.nextNode();
				String s=nd.getFirstChild().toString();
				Text tx=(Text)nd.getFirstChild();
				tx.setData(dataSourceJNDI);
				s=nd.getFirstChild().toString();
				OutputFormat format = new OutputFormat(doc);
				ByteArrayOutputStream out=new ByteArrayOutputStream();
				XMLSerializer output = new XMLSerializer(out, format);
				output.serialize(doc);
				JarUtils jutil=new JarUtils(fileName);
				jutil.addFileToJar("META-INF/jonas-ejb-jar.xml",new ByteArrayInputStream(
						out.toByteArray()));
				jutil.store();
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {
				String[] signature={"java.lang.String"};
				String[] params=new String[1];
				params[0] = fileName;
				query = new ObjectName("jonas:j2eeType=J2EEServer,*");
				ObjectName server=(ObjectName)mgmt.queryNames(query, null).iterator().next();
				String deployedName=(String)mgmt.invoke(server, "deployJar", params, signature);
				query=new ObjectName(deployedName);
				ObjectName module=(ObjectName)mgmt.queryNames(query, null).iterator().next();
				String[] allEjb=(String[])mgmt.getAttribute(module, "ejbs");
				
				String qString=allEjb[0];
				query=new ObjectName(qString+",*");
				ObjectName res=(ObjectName)mgmt.queryNames(query, null).iterator().next();
				core=res;
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
						
		}
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.EJB__DATA_SOURCE_JNDI, oldDataSourceJNDI, dataSourceJNDI));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case JOnASPackage.EJB__JNDI_NAME:
				return getJndiName();
			case JOnASPackage.EJB__FILE_NAME:
				return getFileName();
			case JOnASPackage.EJB__LOCAL_CLASS:
				return getLocalClass();
			case JOnASPackage.EJB__LOCAL_HOME_CLASS:
				return getLocalHomeClass();
			case JOnASPackage.EJB__HOME_CLASS:
				return getHomeClass();
			case JOnASPackage.EJB__EJB_CLASS:
				return getEjbClass();
			case JOnASPackage.EJB__CACHE_SIZE:
				return new Integer(getCacheSize());
			case JOnASPackage.EJB__POOL_SIZE:
				return new Integer(getPoolSize());
			case JOnASPackage.EJB__MAX_CACHE_SIZE:
				return new Integer(getMaxCacheSize());
			case JOnASPackage.EJB__MIN_POOL_SIZE:
				return new Integer(getMinPoolSize());
			case JOnASPackage.EJB__DISPLAY_NAME:
				return getDisplayName();
			case JOnASPackage.EJB__DATA_SOURCE_JNDI:
				return getDataSourceJNDI();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case JOnASPackage.EJB__JNDI_NAME:
				setJndiName((String)newValue);
				return;
			case JOnASPackage.EJB__FILE_NAME:
				setFileName((String)newValue);
				return;
			case JOnASPackage.EJB__LOCAL_CLASS:
				setLocalClass((String)newValue);
				return;
			case JOnASPackage.EJB__LOCAL_HOME_CLASS:
				setLocalHomeClass((String)newValue);
				return;
			case JOnASPackage.EJB__HOME_CLASS:
				setHomeClass((String)newValue);
				return;
			case JOnASPackage.EJB__EJB_CLASS:
				setEjbClass((String)newValue);
				return;
			case JOnASPackage.EJB__CACHE_SIZE:
				setCacheSize(((Integer)newValue).intValue());
				return;
			case JOnASPackage.EJB__POOL_SIZE:
				setPoolSize(((Integer)newValue).intValue());
				return;
			case JOnASPackage.EJB__MAX_CACHE_SIZE:
				setMaxCacheSize(((Integer)newValue).intValue());
				return;
			case JOnASPackage.EJB__MIN_POOL_SIZE:
				setMinPoolSize(((Integer)newValue).intValue());
				return;
			case JOnASPackage.EJB__DISPLAY_NAME:
				setDisplayName((String)newValue);
				return;
			case JOnASPackage.EJB__DATA_SOURCE_JNDI:
				setDataSourceJNDI((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case JOnASPackage.EJB__JNDI_NAME:
				setJndiName(JNDI_NAME_EDEFAULT);
				return;
			case JOnASPackage.EJB__FILE_NAME:
				setFileName(FILE_NAME_EDEFAULT);
				return;
			case JOnASPackage.EJB__LOCAL_CLASS:
				setLocalClass(LOCAL_CLASS_EDEFAULT);
				return;
			case JOnASPackage.EJB__LOCAL_HOME_CLASS:
				setLocalHomeClass(LOCAL_HOME_CLASS_EDEFAULT);
				return;
			case JOnASPackage.EJB__HOME_CLASS:
				setHomeClass(HOME_CLASS_EDEFAULT);
				return;
			case JOnASPackage.EJB__EJB_CLASS:
				setEjbClass(EJB_CLASS_EDEFAULT);
				return;
			case JOnASPackage.EJB__CACHE_SIZE:
				setCacheSize(CACHE_SIZE_EDEFAULT);
				return;
			case JOnASPackage.EJB__POOL_SIZE:
				setPoolSize(POOL_SIZE_EDEFAULT);
				return;
			case JOnASPackage.EJB__MAX_CACHE_SIZE:
				setMaxCacheSize(MAX_CACHE_SIZE_EDEFAULT);
				return;
			case JOnASPackage.EJB__MIN_POOL_SIZE:
				setMinPoolSize(MIN_POOL_SIZE_EDEFAULT);
				return;
			case JOnASPackage.EJB__DISPLAY_NAME:
				setDisplayName(DISPLAY_NAME_EDEFAULT);
				return;
			case JOnASPackage.EJB__DATA_SOURCE_JNDI:
				setDataSourceJNDI(DATA_SOURCE_JNDI_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case JOnASPackage.EJB__JNDI_NAME:
				return JNDI_NAME_EDEFAULT == null ? jndiName != null : !JNDI_NAME_EDEFAULT.equals(jndiName);
			case JOnASPackage.EJB__FILE_NAME:
				return FILE_NAME_EDEFAULT == null ? fileName != null : !FILE_NAME_EDEFAULT.equals(fileName);
			case JOnASPackage.EJB__LOCAL_CLASS:
				return LOCAL_CLASS_EDEFAULT == null ? localClass != null : !LOCAL_CLASS_EDEFAULT.equals(localClass);
			case JOnASPackage.EJB__LOCAL_HOME_CLASS:
				return LOCAL_HOME_CLASS_EDEFAULT == null ? localHomeClass != null : !LOCAL_HOME_CLASS_EDEFAULT.equals(localHomeClass);
			case JOnASPackage.EJB__HOME_CLASS:
				return HOME_CLASS_EDEFAULT == null ? homeClass != null : !HOME_CLASS_EDEFAULT.equals(homeClass);
			case JOnASPackage.EJB__EJB_CLASS:
				return EJB_CLASS_EDEFAULT == null ? ejbClass != null : !EJB_CLASS_EDEFAULT.equals(ejbClass);
			case JOnASPackage.EJB__CACHE_SIZE:
				return cacheSize != CACHE_SIZE_EDEFAULT;
			case JOnASPackage.EJB__POOL_SIZE:
				return poolSize != POOL_SIZE_EDEFAULT;
			case JOnASPackage.EJB__MAX_CACHE_SIZE:
				return maxCacheSize != MAX_CACHE_SIZE_EDEFAULT;
			case JOnASPackage.EJB__MIN_POOL_SIZE:
				return minPoolSize != MIN_POOL_SIZE_EDEFAULT;
			case JOnASPackage.EJB__DISPLAY_NAME:
				return DISPLAY_NAME_EDEFAULT == null ? displayName != null : !DISPLAY_NAME_EDEFAULT.equals(displayName);
			case JOnASPackage.EJB__DATA_SOURCE_JNDI:
				return DATA_SOURCE_JNDI_EDEFAULT == null ? dataSourceJNDI != null : !DATA_SOURCE_JNDI_EDEFAULT.equals(dataSourceJNDI);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (jndiName: ");
		result.append(jndiName);
		result.append(", fileName: ");
		result.append(fileName);
		result.append(", localClass: ");
		result.append(localClass);
		result.append(", localHomeClass: ");
		result.append(localHomeClass);
		result.append(", homeClass: ");
		result.append(homeClass);
		result.append(", ejbClass: ");
		result.append(ejbClass);
		result.append(", cacheSize: ");
		result.append(cacheSize);
		result.append(", poolSize: ");
		result.append(poolSize);
		result.append(", maxCacheSize: ");
		result.append(maxCacheSize);
		result.append(", minPoolSize: ");
		result.append(minPoolSize);
		result.append(", displayName: ");
		result.append(displayName);
		result.append(", dataSourceJNDI: ");
		result.append(dataSourceJNDI);
		result.append(')');
		return result.toString();
	}
	
	
} //EJBImpl
